package com.yowasa.xiuxian.engine.battle.strategy.skill.fire;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.BuffContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.entity.enums.StageEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name="灼魂咒",upAbility = 4,needTravel = 1000)
@Order(1004)
@Component
public class ZhuoHunZhou extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;
    @Override
    public ElementEnum getElement() {
        return ElementEnum.FIRE;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int orgAtk = first.getBattleInfo().getSpell();
        int def = second.getBattleInfo().getRes();
        int atk = orgAtk;
        int dmg = battleHelper.calSpell(atk, def);
        battleHelper.autoAction(this, first, second, content, dmg, "灼魂咒");
        BuffContent zhuoHun = second.getBuff().get("灼魂");
        if (zhuoHun == null) {
            BuffContent buffContent = new BuffContent();
            buffContent.setDuration(5);
            buffContent.setNum(1);
            buffContent.setPositive(false);
            second.getBuff().put("灼魂", buffContent);
        }else {
            zhuoHun.setDuration(5);
            int num=zhuoHun.getNum() + 1;
            if (num > 3) {
                zhuoHun.setNum(3);
            } else {
                zhuoHun.setNum(num);
            }
        }
    }

    @Override
    public void limit(UserBO user) {
        if (user.getElement().get("火") < XiuxianConstants.DEFAULT_ELEMENT_ACTIVITY) {
            throw new HandlerException("学习/使用灼魂咒必须具有火灵根");
        }
        if (user.getStage() < StageEnum.ZHU_JI.getLevel()) {
            throw new HandlerException("学习/使用灼魂咒至少要始明之青");
        }
    }
    @Override
    public String limitDesc() {
        return "达到始明之青且具有火灵根";
    }

    @Override
    public String desc() {
        return "造成伤害时给对方附加一层持续5回合的灼魂debuff,每层灼魂使对方治疗效率降低30%,最多叠加3层,在对方回合开始时对其造成0.1*术法*层数的真实伤害";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        return true;
    }
}
